<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<title>账号设置</title>
<link href="jquery-mobile/jquery.mobile.min.css" rel="stylesheet" type="text/css"/>
<script src="jquery-mobile/jquery.min.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile.min.js" type="text/javascript"></script>
<script src="cordova.js" type="text/javascript"></script>
<script type="text/javascript">
function back(){
	if (typeof(navigator) != 'undefined' && typeof(navigator.app) != 'undefined' && typeof(navigator.app.backHistory) == 'function') {
		navigator.app.backHistory();
	} else{
		history.back();
	}
}

$(document).ready(function(){
	jQuery('body').live('swipeleft',function(event){
		back();
		//event.preventDefault();
	});
	jQuery('body').live('swiperight',function(event){
		window.history.forward();
		//event.preventDefault();
	});
	
	$("#qqframe").css('width', document.body.clientWidth);
	$("#qqframe").css('height', document.body.clientHeight - $("#qqframe").offset().top);
});

$('.ui-btn-back').live('tap',function() {
	back();
	return false;
}).live('click',function() {
	back();
	return false;
});


</script>

</head>
<body>
<div data-role="page">
	 <div data-role="header"  data-theme="b">
    <a href="#" class="ui-btn-back">返回</a>
    <h1>腾讯微博</h1>
   </div>
   <div date-role="content">
     <iframe id="qqframe"
	     src="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=100284268&redirect_uri=http://ihavecar.sinaapp.com/oauth/qq_callback.php&scope=get_user_info,add_share,list_album,add_album,upload_pic,add_topic,add_one_blog,add_weibo">
     </iframe>
   </div>
</div>

<script type="text/javascript">
window.onmessage=function(e) {
	var json_str = e.data;
	var access_token = json_str.access_token;
	var uid = json_str.uid;
	var image = json_str.image;
	var nickname = json_str.name;
	$.ajax({type:'POST',async:false, url:'http://ihavecar.sinaapp.com/postuser.php?nickname='+nickname+'&photo='+image+'&qq='+uid+'&uid='+uid+'&sina=0'});
	//writefile();
	window.location.href =encodeURI('logined.html?img='+image+'&name='+nickname);
};	
	function writefile(){
	//等待加载PhoneGap
	document.addEventListener("deviceready", onDeviceReady, false);
	//PhoneGap加载完毕
	function onDeviceReady() {
		window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
	}
    //获取newFile目录，如果不存在则创建该目录
	function gotFS(fileSystem) {
		newFile = fileSystem.root.getDirectory("UCAR", {create : true,exclusive : false}, writerFile, fail);		
	}
	//获取newFile目录下面的dataFile.txt文件，如果
	不存在则创建此文件
	function writerFile(newFile) {
		newFile.getFile("dataFile.txt", {create : true,exclusive : false}, gotFileEntry, fail);
	}
	function gotFileEntry(fileEntry) {
		fileEntry.createWriter(gotFileWriter, fail);
	}
	function gotFileWriter(writer) {
		writer.onwrite = function(evt) {
			alert("write success");
		};
		writer.write("access_token:"+access_token+";");
	}
	function fail(error) {
		alert("Failed to retrieve file:" + error.code);
	}
	// 检索一个已存在的文件，如果该文件不存在时则创建该文件
}
	//window.location.href =encodeURI('logined.html?img='+image+'&name='+nickname);
	
</script>
</body>
</html>